var ns, map, app, timer, marqueesHeight, slide, imageBrowser,
    stopscroll, scrollElem, preTop, currentTop, stoptime, leftElem, popup;
app = new Vue({
    el: '#app',
    data: {
        form: {
            pageindex: 0,
            pagesize: 10,
            Keywords: '',
            status: 1,//1-待处理 2-已处理
        },
        list: [], 
        isviewhistory: false,
        total: {
            WaitingCount: 0,
            ProcessCount: 0,
        },
        current_item_length: 0,
        can_scroll: false,
    },
    methods: {
        get_data: function() {
            var that = this;
            that.can_scroll = false;
            var options = {};
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.Keywords = that.form.Keywords;
            // options.status = that.form.status;
            if(that.form.status==1){
                options.action = "getreleasenotelist";
            }
            if(that.form.status==2){
                options.action = "getmyhandledreleaseslip";
            }
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.list = data.list;
                    } else {
                        that.list = that.list.concat(data.list);
                    }
                    that.current_item_length = that.list.length;

                    if (that.form.status == 1) {
                        that.total.WaitingCount= data.Unread;
                    }
                    
                    // that.list = data.list;
                    // that.total = data.Unread;
                } else if (err) {
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        do_select_tab: function(status) {
            var that = this;
            that.list=[];
            that.current_item_length = 0;
            that.form.pageindex=0;
            that.form.pagesize=10;
            that.form.status = status;
            that.get_data();
        },
        do_open:function(item){
            var that=this;
            ns.openWin('outdoor_detail','详情',{
                ID:item.ID
            });
            
            //测试扫码后的详情页面，请忽略
            // ns.openWin('scanner_release_frm','放行单详情',{
            //     id:item.ID
            // });
        },
        //审批
        examRelease:function(item,IsReject){
            var that=this;
            var that = this;
            ns.openWin('examine_single', '审批建议', {
                IsReject: IsReject,
                ID: item.ID,
            });   
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.isviewhistory = api.pageParam.isviewhistory || false;
    app.get_data();   
    setTimeout(function () {
        ns.init_pull();
    }, 500)

    api.addEventListener({
        name: 'do_open_add'
    }, function (ret, err) {
        ns.openWin('outdoor_add_frm', '新增放行条', {
            isviewhistory: true,
            // bg: "#289FFF",
            // txtcolor: "#ffffff",
        })
    });

    api.addEventListener({
        name: 'do_load_data'
    }, function (ret, err) {
       app.do_select_tab(2);
    });

};
